package ch.idsia.ai.agents.controllers.myai.tests;

import ch.idsia.ai.agents.controllers.myai.Node;
import org.junit.*;

import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;

/**
 * Created by IntelliJ IDEA.
 * User: Blake
 * Date: Jul 1, 2010
 * Time: 7:46:32 PM
 * To change this template use File | Settings | File Templates.
 */
public class NodeTest
{
    @Test   public void testNode()
    {
        String name;
        for(int i = 0; i < 100; ++i)
        {
            name = "node"+i;
            int random = (int)(Math.random()*100)+1;
            Node testNode = new Node(name, random);
            assertNotNull("testNode", testNode);
            assertTrue("testNode", testNode.getName() == name);
            assertTrue("testNode", testNode.getPointValue() == random);
        }
    }
    
    @Test   public void testAddNode()
    {
        int point = (int)(Math.random()*100)+1;
        Node node = new Node("parent", 0);
        Node child = new Node("child", point);
        node.addNode(child);
        
        assertTrue(node.getNumberOfChildren() == 1);
        assertTrue(node.getNode(0).getName().equals("child"));
        assertTrue(node.getNode(0).getPointValue() == point);
    }

    @Test   public void testGetNumberOfChildren()
    {
        String name;
        int point = 10;
        Node parent = new Node("parent", 0);

        for(int i = 0; i < 100; ++i)
        {
            assertTrue(parent.getNumberOfChildren() == i);
            name = "child"+i;
            parent.addNode(new Node(name, point));
        }
    }

    @Test   public void testGetName()
    {
        Node test = new Node("testNode", 10);
        assertTrue(test.getName().equals("testNode"));
    }

    @Test   public void testGetNode()
    {
        Node parent = new Node("parent", 5);
        Node child = new Node("child", 10);
        parent.addNode(child);

        assertTrue(parent.getNode(0).getName().equals("child"));
        assertTrue(parent.getNode(0).getPointValue() == 10);       
    }

    @Test   public void testRemoveNode()
    {
        Node parent = new Node("parent", 10);

        for(int i = 0; i < (int)(Math.random()*100)+1; ++i)
        {
            parent.addNode(new Node("child"+i, i));
        }

        int num = parent.getNumberOfChildren();
        parent.removeNode(num - 1);

        assertTrue(parent.getNumberOfChildren() == num - 1);
    }

    @Test   public void testGetPointValue()
    {
        for(int i = 0; i < 100; ++i)
        {
            int point = (int)(Math.random()*100)+1;
            Node node = new Node("name", point);

            assertTrue(node.getPointValue() == point);
        }
    }
}
